package com.dsg.controller;

import com.dsg.entity.Customer;
import com.dsg.entity.Staff;
import com.dsg.service.CustomerService;
import com.dsg.utils.Log;
import com.dsg.vo.CustomerDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
@Controller
public class CustomerController {
    private String msg;
    @Resource
    private CustomerService customerService;
    @GetMapping("/aaa")
    public String kehu(){
        return "cus/khzygl";
    }
    @GetMapping(value = "list")
    @ResponseBody
    public List<Customer> list(CustomerDto customerDto){
          List<Customer> list=  customerService.seachAll(customerDto);
//          list.forEach(System.out::println);
          return list;
    }
    @GetMapping("/allYg")
    @ResponseBody
    public List<Staff> allYg(){
        return customerService.seachAllYg();

    }
    @GetMapping("/batchDelcus")
    @ResponseBody
    public String batchDel(Integer [] ids){
        try {
            customerService.batchDel(ids);
            msg="删除成功！";
        }catch (Exception ex){
            msg="删除失败！";
        }
        return msg;
    }
    @GetMapping("/upStaff")
    @ResponseBody
    public String updateStaff(Customer customer){
        try{
        customerService.updateStaff(customer);
            msg="分配成功！";
        }catch (Exception ex){
            msg="分配失败！";
        }
        return msg;
    }
}
